package com.deliveryservicesystem.service.impl;

import com.deliveryservicesystem.model.Customer;
import com.deliveryservicesystem.model.Product;
import com.deliveryservicesystem.model.Subscription;
import com.deliveryservicesystem.service.Report2;
import com.deliveryservicesystem.service.crud.impl.SubscriptionCrudServiceImpl;
import java.util.List;

/**
 * File Name: Report2Impl.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.service.impl
 * Author: Lance
 * Date: Jul 28, 2012
 * Editor:
 */
public class Report2Impl implements Report2
{

    @Override
    public String getCustomerProducts(String custNo)
    {
        int productCount = 0;
        double productCost = 0;
        StringBuilder reportData = new StringBuilder();
        SubscriptionCrudServiceImpl crudService = new SubscriptionCrudServiceImpl();
        List<Subscription> subscriptions = crudService.findEntities();
        for (Subscription subscription : subscriptions)
        {
            Customer customer = subscription.getCustomerNo();
            if (customer.getCustomerNo() == Integer.parseInt(custNo))
            {
                List<Product> productList = subscription.getProductList();
                for (Product product : productList)
                {
                    reportData.append(product.toString()).append("\n");
                    productCount++;
                    productCost += product.getProductPrice();
                }
                reportData.append("\n");
            }
        }
        reportData.append("Report Summary\n====================\nTotal Cost: ").append(productCost).append("\nTotal Products:").append(productCount);
        return reportData.toString();
    }
}
